//config的设置是全局的
layui.config({
    base: '/js/plugins/' // 自定义扩展插件所在的目录
}).extend({ //设定模块别名
    yjsloading: 'yjsloading',
    yjslayer: 'yjslayer',
    yjsupload: 'yjsupload',
});

layui.use(['form', 'yjslayer', 'yjsloading', 'yjsupload'], function () {
    var $ = layui.jquery
        , form = layui.form
        , yjslayer = layui.yjslayer
        , yjsloading = layui.yjsloading
        , yjsupload = layui.yjsupload;

    // 自定义表单验证规则
    form.verify({});

    // 重新获取验证码
    $('.getLVcode').click(function () {
        var url = '/vcode/path/form';
        yjsloading.loadingCaptcha(url);
    });

    // 监听部门信息表单确定按钮事件
    form.on('submit(toolbarEvent)', function (data) {
        var eventType = data.field.viewType;
        var url, msg = '';

        switch (eventType) {
            case "importNewArrivals":
                url = '/import/newarrivals';
                msg = '您确定执行本次数据导入操作吗？';
                postData = data.field;
                break;
            case "importMajors":
                url = '/import/majors';
                msg = '您确定执行本次数据导入操作吗？';
                postData = data.field;
                break;
            case "importNewStudents":
                url = '/import/newstudents';
                msg = '您确定执行本次数据导入操作吗？';
                postData = data.field;
                break;
            case "importClothes":
                url = '/import/clothes';
                msg = '您确定执行本次数据导入操作吗？';
                postData = data.field;
                break;
            case "importClothesSize":
                url = '/import/clothes/size';
                msg = '您确定执行本次数据导入操作吗？';
                postData = data.field;
                break;
            case "importDailyUses":
                url = '/import/dailyuses';
                msg = '您确定执行本次数据导入操作吗？';
                postData = data.field;
                break;
            case "importPays":
                url = '/import/pays';
                msg = '您确定执行本次数据导入操作吗？';
                postData = data.field;
                break;
            case "importReports":
                url = '/import/reports';
                msg = '您确定执行本次数据导入操作吗？';
                postData = data.field;
                break;
            case "importTextbooks":
                url = '/import/textbooks';
                msg = '您确定执行本次数据导入操作吗？';
                postData = data.field;
                break;
            case "importTimetables":
                url = '/import/timetables';
                msg = '您确定执行本次数据导入操作吗？';
                postData = data.field;
                break;
            case "importMajorsResult":
                url = '/import/majors/result';
                msg = '您确定执行本次数据导入操作吗？';
                postData = data.field;
                break;
            case "importDormsResult":
                url = '/import/dorms/result';
                msg = '您确定执行本次数据导入操作吗？';
                postData = data.field;
                break;
            case "importClassesResult":
                url = '/import/classes/result';
                msg = '您确定执行本次数据导入操作吗？';
                postData = data.field;
                break;
            case "importDepartment":
                url = '/import/departments';
                msg = '您确定执行本次数据导入操作吗？';
                postData = data.field;
                break;
            case "importFaculty":
                url = '/import/faculties';
                msg = '您确定执行本次数据导入操作吗？';
                postData = data.field;
                break;
            case "importTerm":
                url = '/import/terms';
                msg = '您确定执行本次数据导入操作吗？';
                postData = data.field;
                break;
            case "importSchool":
                url = '/import/graduated_school';
                msg = '您确定执行本次数据导入操作吗？';
                postData = data.field;
                break;
        }
        title = '批量信息导入';

        yjsloading.ajaxImportConfirm(title, msg, url, postData, function (result) {
            $('#rspStatus').val(result['rspStatus']);
            $('#rspMsg').val(result['rspMsg']);
        });
    });

    // 监听个人信息表单取消按钮事件
    $('.cancelEvent').click(function () {
        var title, msg = '';
        title = '导入信息维护';
        msg = '您确定取消本次数据更新操作吗？';
        yjsloading.cancelConfirm(title, msg);
    });

    // 文件上传事件 （有问题，url需要根据参数改变）
    $elem = '#excelFile';
    $url = '/upload/files';
    $userCode = $("[name='code']").val();
    $data = {code: $userCode};
    yjsupload.uploadExcel($elem,$url,$data);
});